package Practice;

public class Queue<Item>
{
	private Node<Item> last;

	private static class Node<Item>
	{
		public Item item;
		public Node<Item> next;
	}

	public Queue()
	{
		last = null;
	}

	public void enqueue(Item item)
	{
		if (last == null)
		{
			last = new Node<Item>();
			last.next = last;
			last.item = item;
		} else
		{
			Node<Item> node = new Node<Item>();
			node.next = last.next;
			node.item = item;
			last.next = node;
			last = node;
		}
	}

	public Item dequeue()
	{
		Item item = last.next.item;
		if (last == last.next)
		{
			last = null;
		} else
		{
			last.next = last.next.next;
		}
		return item;
	}

	public boolean isEmpty()
	{
		return last == null;
	}
	
	public Node<Item> reverse(Node<Item> node)
	{
		if (node==null)
		{
			return null;
		}
		Node<Item> first =node;
		node=node.next;
		Node<Item> temp=null;
		while(node!=null)
		{
			first.next=temp;
			temp=first;
			first=node;
			node=first.next;
		}
		return first;
	}
	
	public static void main(String[] args)
	{
		
	}
}
